package Inherit;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86184
 * Date: 2023-02-12
 * Time: 14:32
 */
class Animal2{
    public String name;
    public int age;

    static {  //静态代码块
        System.out.println("Animal2::Static");
    }

    {  //代码块
        System.out.println("Animal2::f");
    }

    public Animal2(String name, int age) {  //构造方法
        this.name = name;
        this.age = age;
        System.out.println("Animal2::");
    }

    public void eat(){
        System.out.println(name+"正在吃饭"+" 年龄："+age);
    }
}
class Dog2 extends Animal2{
    public String silly;

    static {  //静态代码块
        System.out.println("Dog2::Static");
    }

    {  //代码块
        System.out.println("Dog2::f");
    }

    public Dog2(String name, int age, String silly) {
        super(name, age);  //必须在最前面
        this.silly = silly;
        System.out.println("Dog2::");
    }

    public void barks(){
        System.out.println(name+"汪汪叫");
    }
}
class Cat2 extends Animal2{

    static {  //静态代码块
        System.out.println("Cat2::Static");
    }

    {  //代码块
        System.out.println("Cat2::f");
    }

    public Cat2(){  //不带参数的构造方法
        super("咪咪",10);
        System.out.println("Cat2::0");
    }
    public Cat2(String name,int age){  //带参数的构造方法
        super(name,age);
        System.out.println("Cat2::2");
    }
    public void catchMouse(){
        System.out.println(name+" 正在抓老鼠");
    }
}
public class Text2 {
    public static void main(String[] args) {

        //先执行父类的静态代码块，在执行子类的静态代码块，然后执行父类的代码块、构造方法，最后执行子类的代码块、构造方法
        Dog2 dog2=new Dog2("旺财",10,"false");
        System.out.println("=========================");
        //在次形成对象就不在执行静态代码块（静态代码块只执行一次）
        Dog2 dog3=new Dog2("旺财",10,"false");
        System.out.println("=========================");
        Cat2 cat2=new Cat2();
    }
}
